/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 luck_icon_window.cpp

	$Header: /heroes4/luck_icon_window.cpp $

	$NoKeywords: $

 ************************************************************************/
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "luck_icon_window.h"

#include "bitmap_group_cache.h"
#include "creature_stack.h"
#include "external_string.h"
#include "format_string.h"

// -----------------------------------------------------------------
// class to display & give information about morale
// -----------------------------------------------------------------
extern t_bitmap_group_cache const		k_morale_icons_44;
extern t_bitmap_group_cache const		k_morale_icons_34;
t_external_string const k_text_luck( "luck.dialog" );
t_external_string const k_text_neutral_luck( "neutral_luck.dialog" );
t_external_string const	k_text_luck_help( "luck.help" );


static t_bitmap_group_ptr get_icons( int height )
{
	if (height < 44)
		return k_morale_icons_34.get();
	return k_morale_icons_44.get();
}

t_luck_icon_display::t_luck_icon_display( t_screen_rect const& rect, t_window* parent, 
										  int value )
                  : t_bitmap_group_window( get_icons( rect.height() ), rect.top_left(),
					                         0, parent )
{
	set_value( value );
	set_right_click_text( k_text_luck_help );
}

void t_luck_icon_display::set_value( int luck )
{
	std::string help_text;

	set_frame( format_string( "%i luck", luck ) );
	if (luck != 0)
		help_text = format_string( "%+i ", luck ) + k_text_luck.get();
	else
		help_text = k_text_neutral_luck.get();
	set_help_balloon_text( help_text );
}

// -----------------------------------------------------------------
// class to display & give information about morale
// -----------------------------------------------------------------
void t_luck_icon_window::set_creature( t_creature_stack const* creature )
{
	if (m_creature == creature)
		return;
	m_creature = creature;
	update();

}

// -----------------------------------------------------------------
// class to display & give information about morale
// -----------------------------------------------------------------
void t_luck_icon_window::update()
{
	if (m_creature == 0)
		return;

	set_value( m_creature->get_luck() );
}

